package hn.cch.framework.akka;

import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedAbstractActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;

public class ConsumerActor extends UntypedAbstractActor {

    private LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);

    private ActorRef functionActor = getContext().actorOf(Props.create(FunctionActor.class), "functionActor");

    @Override
    public void onReceive(Object message) throws Throwable {
        if (message.equals("function")) {
            log.info("onReceive:function");
            functionActor.tell(new Request(), getSelf());
        } else if (message instanceof Response) {
            Response response = (Response) message;
            log.info("response:{}", response.getResult());
        } else {
            log.error("onReceive:{}", message);
        }
    }
}
